package com.jms.logger.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.jms.logger.dao.LoggerDao;
import com.jms.logger.po.LoggerInfo;

@Repository("loggerDao")
public class LoggerDaoImpl implements LoggerDao {
	
	/**
	 * 通过Spring引入JPA需要的entityManage对象
	 */
	@Autowired(required=true)
	@PersistenceContext(name="unitName")
	private EntityManager entityManager;
	
	@Override
	public List<LoggerInfo> showLogger() {
		String jpa_sql = "select loggerInfo from com.jms.logger.po.LoggerInfo loggerInfo";
		List<LoggerInfo> lists_logger = entityManager.createQuery(jpa_sql).getResultList();
		System.out.println(lists_logger);
		entityManager.close();
		return lists_logger;
	}

	@Override
	public void addLogger(LoggerInfo loggerInfo) {
		entityManager.persist(loggerInfo);
		entityManager.close();
	}
	
}
